layui.use(['form', 'layer'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    $.ajax({
        url: $.cookie("tempUrl") + "doctororder/findPrescriptionDetailsVO?id=" + $.cookie('tempId'),
        type: "POST",
        success: function (result) {
            if (result.code === 200) {

                //第一模块
                $(".no").append(result.data.no);
                $(".createTime").append(result.data.createTime);
                $(".name").append(result.data.name);
                $(".gender").append(result.data.gender === 1 ? "男" : "女");
                $(".age").append(result.data.age);
                $(".distribution").append(result.data.distribution);
                $(".blh").append(result.data.blh);
                $(".departmentName").append(result.data.departmentName);
                $(".detailsAddress").append(result.data.detailsAddress);
                $(".preliminaryDiagnosis").append(result.data.preliminaryDiagnosis);

                //第二模块 RP
                let list = result.data.doctorOrderDrugTiemVOList;
                for (let index in list) {
                    let titleNum = parseInt(index) + 1;
                    $(".doctorOrderDrugTiemVOList").append("<div class=\"layui-left \" style=\"padding-top: 10px\"><a class=\"layui-btn layui-btn-primary layui-border-black layui-btn-xs\">"
                        + titleNum + "." + list[index].name
                        + "，" + list[index].specifications + "X" + list[index].conversionCoefficient + list[index].drunit
                        + "，" + list[index].number + list[index].packagingUnit
                        + "，" + list[index].usages
                        + "，一次" + list[index].dosage + list[index].drunit
                        + "，" + list[index].frequency
                        + "，" + "用药" + list[index].useDays + "天"
                        + "</a></div>");
                }

                //第三模块
                $(".doctorName").append(result.data.doctorName);
                $(".sydoctorName").append(result.data.sydoctorName);
                $(".fhdoctorName").append(result.data.fhdoctorName);
                for (let index in result.data.list) {
                    // console.log(index)
                    $(".list").append(result.data.list[index]);
                }
                let profession;
                switch (result.data.profession) {
                    case 1:
                        profession = '上班族';
                        break;
                    case 2:
                        profession = '个体户';
                        break;
                    case 3:
                        profession = '企业主';
                        break;
                    case 4:
                        profession = '无固定职业';
                        break;
                }
                $(".profession").val(profession);
                $(".id_front").attr("src", result.data.idFront);  //身份证
                $(".id_back").attr("src", result.data.idBack);  //身份证
            } else {
                //域外
                $.ajax({
                    url: $.cookie("tempUrl") + "doctororder/findJwPrescriptionDetailsVO?id=" + $.cookie('tempId'),
                    type: "POST",
                    success: function (result) {
                        if (result.code === 200) {

                            //第一模块
                            $(".no").append(result.data.id);
                            $(".createTime").append(result.data.createTime);
                            $(".name").append(result.data.menberName);
                            $(".gender").append(result.data.gender === 1 ? "男" : "女");
                            $(".age").append(result.data.menberAge);
                            $(".distribution").append(result.data.distribution);
                            $(".blh").append(result.data.blh);
                            $(".departmentName").append(result.data.departmentName);
                            $(".detailsAddress").append(result.data.detailsAddress);
                            $(".preliminaryDiagnosis").append(result.data.preliminaryDiagnosis);

                            //第二模块 RP
                            let list = result.data.doctorOrderDrugTiemVOList;
                            for (let index in list) {
                                let titleNum = parseInt(index) + 1;
                                $(".doctorOrderDrugTiemVOList").append("<div class=\"layui-left \" style=\"padding-top: 10px\"><a class=\"layui-btn layui-btn-primary layui-border-black layui-btn-xs\">"
                                    + titleNum + "." + list[index].name
                                    + "，" + list[index].specifications + "X" + list[index].conversionCoefficient + list[index].drunit
                                    + "，" + list[index].number + list[index].packagingUnit
                                    + "，" + list[index].usages
                                    + "，一次" + list[index].dosage + list[index].drunit
                                    + "，" + list[index].frequency
                                    + "，" + "用药" + list[index].useDays + "天"
                                    + "</a></div>");
                            }

                            //第三模块
                            $(".doctorName").append(result.data.doctorName);
                            $(".sydoctorName").append(result.data.trialDrug);
                            $(".fhdoctorName").append(result.data.fuheDrug);
                            for (let index in result.data.list) {
                                // console.log(index)
                                $(".list").append(result.data.list[index]);
                            }
                            let profession;
                            switch (result.data.profession) {
                                case 1:
                                    profession = '上班族';
                                    break;
                                case 2:
                                    profession = '个体户';
                                    break;
                                case 3:
                                    profession = '企业主';
                                    break;
                                case 4:
                                    profession = '无固定职业';
                                    break;
                            }
                            $(".profession").val(profession);
                            $(".id_front").attr("src", result.data.idFront);  //身份证
                            $(".id_back").attr("src", result.data.idBack);  //身份证
                        } else {
                            layer.msg(result.msg, {icon: 7, anim: 6});
                        }
                    }
                });
            }
        }
    });

    form.on("submit(addNews)", function (data) {
        //do something
        $(".addNews").css("display", "none")
        layer.msg("下载中..")

        //下载图片
        doScreenShot2()

        // //截屏
        // html2canvas($('body'), {
        //     onrendered: function (canvas) {
        //         var imgString = canvas.toDataURL("image/png");
        //         window.open(imgString);
        //     }
        // });
        return false;
    });
});